cmake_minimum_required(VERSION 3.8)
project(app_interface)

# Default to C++17
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 17)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Qt5 paths (adjust these paths according to your Qt5 installation)
set(ENV{HOME} $ENV{HOME})
set(Qt5_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5")
set(Qt5Core_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5Core")
set(Qt5Gui_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5Gui")
set(Qt5Widgets_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5Widgets")
set(Qt5WebEngineCore_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5WebEngineCore")
set(Qt5WebEngineWidgets_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5WebEngineWidgets")
set(Qt5WebChannel_DIR "$ENV{HOME}/Qt/5.15.2/gcc_64/lib/cmake/Qt5WebChannel")

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(custom_msgs REQUIRED)

# System dependencies
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets WebEngineCore WebEngineWidgets WebChannel Concurrent)
find_package(OpenCV REQUIRED)

# Qt5 automation
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Source files
set(SOURCES
    src/mainwindow.cpp
    src/boatCtlApp.cpp
    src/mapchannel.cpp
    src/gaugecolor.cpp
    src/gaugecompass.cpp
)

# Header files
set(HEADERS 
    include/mainwindow.h
    include/mapchannel.h
    include/gaugecolor.h
    include/gaugecompass.h
)

# UI files
set(FORMS
    src/mainwindow.ui
)

# Resource files
set(RESOURCES
    qrc/res.qrc
)

# Include directories
include_directories(
  include
  ${OpenCV_INCLUDE_DIRS}
  ${Qt5Core_INCLUDE_DIRS}
  ${Qt5Gui_INCLUDE_DIRS}
  ${Qt5Widgets_INCLUDE_DIRS}
  ${Qt5WebEngineCore_INCLUDE_DIRS}
  ${Qt5WebEngineWidgets_INCLUDE_DIRS}
  ${Qt5WebChannel_INCLUDE_DIRS}
  ${Qt5Concurrent_INCLUDE_DIRS}
)

# Create executable
add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} ${FORMS} ${RESOURCES})

# Specify dependencies for the executable
ament_target_dependencies(${PROJECT_NAME}
  rclcpp
  rclpy
  sensor_msgs
  cv_bridge
  ament_index_cpp
  custom_msgs
)

# Link libraries
target_link_libraries(${PROJECT_NAME} 
  ${OpenCV_LIBS}
  Qt5::Core 
  Qt5::Gui 
  Qt5::Widgets 
  Qt5::WebEngineCore 
  Qt5::WebEngineWidgets 
  Qt5::WebChannel 
  Qt5::Concurrent
)

# Install
install(TARGETS ${PROJECT_NAME}
  DESTINATION lib/${PROJECT_NAME}
)

# Install launch files, config files, etc.
install(DIRECTORY
  # launch
  # config
  DESTINATION share/${PROJECT_NAME}/
)

# Testing
if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()